package Package.Example.ReflectionGetsMemberVariablesAndUses;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class ReflectionGetsMemberVariablesAndUsesx {
    public static final void ReflectionGetsMemberVariablesAndUses () throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException {
        Class<?> c=Class.forName("Package.Example.GetsTheConstructorAndUses.Student");
        Constructor<?> con=c.getConstructor();
        Object obj=con.newInstance();

        Field getNames=c.getDeclaredField("name");
        getNames.setAccessible(true);
        getNames.set(obj,"ChangCun");
        System.out.println(obj);

        Field getAddresses=c.getDeclaredField("address");
        getAddresses.setAccessible(true);
        getAddresses.set(obj,"China");
        System.out.println(obj);

        Field getAges=c.getDeclaredField("age");
        getAges.setAccessible(true);
        getAges.set(obj,16);
        System.out.println(obj);
    }
}
